package com.hnkywl.sts.action.organ;

import com.hnkywl.sts.entity.organ.Ck;
import com.hnkywl.sts.service.organ.CkService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created with IntelliJ IDEA.
 * User: jerry
 * Date: 13-3-28
 * Time: 下午3:39
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/organ/ck")
public class CkAction extends SimpleActionSupport {
    private CkService ckService;
    //仓库
    private Ck ck;
    //仓库名称
    private String mc;
    //所属公司机构名称
    private String ssgsjg;
    //所属公司机构Id
    private Long ssgsjgId;
    //传入的id值
    private Long ckId;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;
    //行索引
    private int index;
    //远程ajax验证的值
    private String validateVal;
    //需要远程ajax验证的属性
    private String validateField;

    private Long gsId;

    //仓库的查询分页
    @Action("ckList")
    public void ckList() {
        this.renderJson(this.ckService.findAllCk(mc, ssgsjg, ssgsjgId, page, rows));
    }

    //仓库明细
    @Action("ckmcXsdList")
    public void ckmcXsdList() {
        this.renderJson(this.ckService.findSerchCkmc(ssgsjgId));
    }

    //仓库明细
    @Action("ckmcList")
    public void ckmcList() {
        this.renderJson(this.ckService.findAllCkmc(ssgsjgId));
    }

    @Action("sskcCkmcList")
    public void sskcCkmcList() {
        this.renderJson(this.ckService.findAllCkmc(gsId));
    }

    @Action("sskcCkmcForSskc")
    public void sskcCkmcForSskc(){
        this.renderJson(this.ckService.sskcCkmcForSskc(gsId));
    }

    @Action("sskcCkmcListForSearch")
    public void sskcCkmcListForSearch() {
        this.renderJson(this.ckService.findSerchCkmcForGsjg(gsId));
    }

    //仓库明细
    @Action("bgckmcList")
    public void bgckmcList() {
        this.renderJson(this.ckService.findAllBgCkmc());
    }

    //findYwsfcCkList
    //业务收发存仓库
    @Action("ywsfckmcList")
    public void ywsfckmcList() {
        this.renderJson(this.ckService.findYwsfcCkList());
    }

    //仓库明细
    @Action("ckSearch")
    public void ckSerch() {
        this.renderJson(this.ckService.findAllCkmc(ssgsjgId));
    }

    @Action("ck_content")
    public String ckContent() {
        //进入update页面
        if (ckId != null) {
            ck = ckService.findCkDetail(ckId);
        } else {
            //进入add页面
            ck = new Ck();
            //新增时自动生成排序号
            ck.setPxh(this.ckService.findNextPxh());
        }
        return SUCCESS;
    }

    /**
     * 方法名:     addCk
     * 功能描述:      向数据库添加仓库
     * 输入参数:
     * 异常:      <RuntimeException  Exception>
     * 创建人:     zsp
     * 创建日期:   13-3-29上午9:47
     * 修改人:     zsp
     * 修改日期:   13-3-29上午9:47
     */
    @Action("add_ck")
    public void addCk() {
        try {
            this.ckService.saveCk(ck);
            renderText("{\"statusCode\":\"200\", \"message\":\"添加仓库成功！\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 方法名:     update_ck
     * 功能描述:      修改仓库
     * 输入参数:
     * 异常:      <RuntimeException  Exception>
     * 创建人:     scl
     * 创建日期:   13-3-29上午11:50
     * 修改人:     scl
     * 修改日期:   13-3-29上午11:50
     */
    @Action("update_ck")
    public void updateCk() {
        try {
            this.ckService.updateCk(ck);
            renderText("{\"statusCode\":\"200\",\"message\":\"修改仓库成功！\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }

    }

    /**
     * 方法名:     deleteCk
     * 功能描述:      删除数据库仓库
     * 输入参数:
     * 异常:      <RuntimeException  Exception>
     * 创建人:     zsp
     * 创建日期:   13-3-29上午11:47
     * 修改人:     zsp
     * 修改日期:   13-3-29上午11:47
     */
    @Action("delete_ck")
    public void deleteCk() {
        try {
            this.ckService.deleteCk(ckId);
            renderText("{\"statusCode\":\"200\", \"message\":\"删除仓库成功！\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 远程ajax验证
     */
    @Action("ajax_validate")
    public void ajaxValidate() {
        if (!ckService.ajaxValidate(ckId, validateField, validateVal))
            renderJson("{\"valid\":true}");
        else
            renderJson("{\"valid\":false}");
    }


    //=========================GetterAndSetter=======================================

    public Ck getCk() {
        return ck;
    }

    public void setCk(Ck ck) {
        this.ck = ck;
    }

    public String getMc() {
        return mc;
    }

    public Long getGsId() {
        return gsId;
    }

    public void setGsId(Long gsId) {
        this.gsId = gsId;
    }

    public void setMc(String mc) {
        this.mc = mc;
    }

    public String getSsgsjg() {
        return ssgsjg;
    }

    public void setSsgsjg(String ssgsjg) {
        this.ssgsjg = ssgsjg;
    }

    public Long getCkId() {
        return ckId;
    }

    public void setCkId(Long ckId) {
        this.ckId = ckId;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public String getValidateVal() {
        return validateVal;
    }

    public void setValidateVal(String validateVal) {
        this.validateVal = validateVal;
    }

    public String getValidateField() {
        return validateField;
    }

    public void setValidateField(String validateField) {
        this.validateField = validateField;
    }

    public Long getSsgsjgId() {
        return ssgsjgId;
    }

    public void setSsgsjgId(Long ssgsjgId) {
        this.ssgsjgId = ssgsjgId;
    }

    @Autowired
    public void setCkService(CkService ckService) {
        this.ckService = ckService;
    }
}
